package impl

import (
	"gitee.com/go-course/go11/devcloud-mini/maudit/apps/log"
	"gitee.com/go-course/go11/devcloud-mini/maudit/conf"
	"github.com/infraboard/mcube/ioc"
	"go.mongodb.org/mongo-driver/mongo"
)

func init() {
	ioc.RegistryController(&impl{})
}

// 显示的约束对象实现接口
var _ log.Service = (*impl)(nil)

type impl struct {
	// ioc
	ioc.IocObjectImpl
	// 依赖col
	col *mongo.Collection
}

func (i *impl) Init() error {
	// 补充Mongo依赖
	db, err := conf.C().MongoDB.GetDB()
	if err != nil {
		panic(err)
	}
	i.col = db.Collection("operate_log")
	return nil
}

func (i *impl) Name() string {
	return log.AppName
}
